package capricornus.components.text
{
	import capricornus.components.label.Label;
	import capricornus.components.sprite.AbstractComponent;
	import capricornus.components.utils.FilterUtils;
	
	import flash.display.LineScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	public class TextInput extends AbstractComponent
	{
		private var _defaultHeight:int = 0;
		private var _textField:TextField;
		
		public function TextInput()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_textField = new TextField();
			_textField.defaultTextFormat = Label.DEFAULT_TEXT_FORMAT;
			_textField.textColor = Label.DEFAULT_TEXT_COLOR;
			_textField.multiline = false;
			_textField.wordWrap = false;
			_textField.filters = FilterUtils.getBlackGlowFilter();
			_textField.text = "是";
			_textField.height = _defaultHeight = _textField.textHeight + 6;
			_textField.text = "";
			_container.addChild( _textField );
			
			enabled = true;
			setSize( 80, 0 )
		}
		
		/**
		 * 设置大小 
		 * @param w
		 * @param h 如果为0，则是默认高度
		 * 
		 */		
		override public function setSize(w:int, h:int):void
		{
			if( h==0 ) h = _defaultHeight;
			_textField.width = w;
			_textField.height = h;
			super.setSize(w, h );
			
			_baseBack.scaleX = _baseBack.scaleY = 1;
			_baseBack.graphics.clear();
			_baseBack.graphics.beginFill(0xff0000,0);
			_baseBack.graphics.lineStyle( 1, 0, 1, true, LineScaleMode.NONE );
			_baseBack.graphics.drawRect( 0, 0, w, h );
			_baseBack.graphics.endFill();
		}
		
		override public function set enabled(value:Boolean):void
		{
			super.enabled = value;
			if( value )
			{
				_textField.type = TextFieldType.INPUT;
			}
			else
			{
				_textField.type = TextFieldType.DYNAMIC;
			}
		}
		
		public function set textColor( value:uint ):void
		{
			_textField.textColor = value;
		}
		
		public function get text():String
		{
			return _textField.text;
		}
		
		public function set text( value:String ):void
		{
			_textField.text = value;
		}
		
		public function get htmlText():String
		{
			return _textField.htmlText;
		}
		
		public function set htmlText( value:String ):void
		{
			_textField.htmlText = value;
		}
	}
}










